from rest_framework import serializers

from areas.models import Areas


class AreasSerializer(serializers.ModelSerializer):
    """地区序列化器类"""

    class Meta:
        model = Areas
        fields = ('id', 'name')


class SubAreasSerializer(serializers.ModelSerializer):
    # 关联对象嵌套序列化器类
    # 下级地区
    subs = AreasSerializer(label='下级地区', many=True)

    class Meta:
        model = Areas
        fields = ('id', 'name', 'subs')
